package com.nervenets.template.event;

import com.nervenets.template.service.DataOfGoldService;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;

@Slf4j
@AllArgsConstructor
public class DataOfGoldEventListener {
    private final DataOfGoldService dataOfGoldService;

    @SneakyThrows
    @Async
    @Order(0)
    @EventListener(DataOfGoldEvent.class)
    public void handle(DataOfGoldEvent event) {
        Thread.sleep(1000);

        DataOfGoldEvent.Type type = (DataOfGoldEvent.Type) event.getSource();
        long total = 0, platformSpend = 0, totalExchange = 0;
        switch (type) {
            case platformSpend:
                break;
            case totalExchange:
                break;
        }
        dataOfGoldService.updateData(total, platformSpend, totalExchange);
    }
}
